﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using StoreTransport.Presentation.Forms;
using StoreTransport.DAO;
using StoreTransport.Business.Helper;

namespace StoreTransport.Presentation.Forms {
    public partial class MDIMainForm : Form {

        public User user { get; set; }

        public MDIMainForm() {
            InitializeComponent();
        }

        private void ClearForms() {
            foreach (Form f in this.MdiChildren) {
                f.Close();
            }
        }

        private void menuMarketList_Click(object sender, EventArgs e) {
            OpenForm(new MarketListForm());
        }

        private void menuASMList_Click(object sender, EventArgs e) {
            OpenForm(new ASMListForm());
        }

        private void menuRegionList_Click(object sender, EventArgs e) {
            OpenForm(new RegionListForm());
        }

        private void menuProductLineList_Click(object sender, EventArgs e) {
            OpenForm(new ProductLineListForm());
        }

        private void menuProductList_Click(object sender, EventArgs e) {
            OpenForm(new ProductListForm());
        }

        private void menuImportMarkets_Click(object sender, EventArgs e) {
            OpenForm(new ImportMarketsForm());
        }

        private void menuImportStoreData_Click(object sender, EventArgs e) {
            OpenForm(new ImportDataForm());
        }

        private void menuImportProducts_Click(object sender, EventArgs e) {
            OpenForm(new ImportProductsForm());
        }

        private void menuProductKindList_Click(object sender, EventArgs e) {
            OpenForm(new ProductKindListForm());
        }

        private void MDIMainForm_Load(object sender, EventArgs e) {
            OpenForm(new LoginForm());
            MainMenuStrip.Visible = false;
            var productLines = CommonHelper.GetContext().ProductLines.OrderBy(c => c.ProductLineName);
            foreach (var productLine in productLines) { 
                ToolStripMenuItem item = new ToolStripMenuItem(productLine.ProductLineName);
                if (CommonHelper.IsWarningProductOrder(productLine.ID)) {
                    menuProductOrder.ForeColor = Color.Red;
                    item.ForeColor = Color.Red;
                }
                item.Name = productLine.ID.ToString();
                item.Click += new EventHandler(menuProductOrderItem_Click);
                menuProductOrder.DropDownItems.Add(item);
            }
        }

        private void menuProductOrderItem_Click(object sender, EventArgs e) {
            string id = ((ToolStripMenuItem)sender).Name;
            Form f = new StoreTransportReportForm(int.Parse(id));
            OpenForm(f);
        }

        private void menuReportStoreTransport_Click(object sender, EventArgs e) {
            OpenForm(new StoreTransportReportForm());
        }

        private void menuReportMarketTransport_Click(object sender, EventArgs e) {
            //OpenForm(new MarketTransportReportForm());
        }

        private void menuReportStoreMarketTransport_Click(object sender, EventArgs e) {
            StoreTransportReportForm f = new StoreTransportReportForm();
            //f.DoStoreFirst = true;
            OpenForm(f);
        }

        private void OpenForm(Form form) {
            ClearForms();
            form.MdiParent = this;
            form.Width = this.Width;
            form.Height = this.Height - MainMenu.Height;
            form.Show();
        }

        private void MenuUserList_Click(object sender, EventArgs e) {
            OpenForm(new UserListForm());
        }

        private void MenuEditUser_Click(object sender, EventArgs e) {
            OpenForm(new EditUser());
        }

        private void menuPermissionList_Click(object sender, EventArgs e) {
            OpenForm(new PermisstionListForm());
        }

        private void menuAreaList_Click(object sender, EventArgs e) {
            OpenForm(new AreaListForm());
        }

        private void menuDBPathConfig_Click(object sender, EventArgs e) {
            OpenForm(new ConfigurationForm());
        }

        private void menuUserHistory_Click(object sender, EventArgs e) {
            OpenForm(new UserHistory());
        }

        private void menuMarketKind_Click(object sender, EventArgs e) {
            OpenForm(new MarketKindListForm());
        }

        private void MainMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) {

        }
    }
}
